package com.sky.controller.admin;

import com.sky.result.Result;
import com.sky.service.Report.ReportService;
import com.sky.vo.OrderCountVO;
import com.sky.vo.SalesTop10ReportVO;
import com.sky.vo.TurnoverVO;
import com.sky.vo.UserCountVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.time.LocalDate;

/**
 * @Author 褚金龙
 * @Date 2024/10/15 21:27
 */
@RestController
@RequestMapping("/admin/report")
@CrossOrigin("*")
@Api(tags = "统计相关接口")
@Slf4j
public class ReportController {
   @Autowired
   private ReportService reportService;
    @GetMapping("/turnoverStatistics")
   @ApiOperation("营业额统计")
    public Result<TurnoverVO> turnoverStatistics(@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate begin,@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate end){

      TurnoverVO turnoverVO=reportService.getTurnoverStatistics(begin,end);
      return Result.success(turnoverVO);
    }


    @GetMapping("/Statistics")
    @ApiOperation("用户数据统计")
    public Result<UserCountVO> UserStatistics(@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate begin, @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate end){

        UserCountVO userCount=reportService.getUserCount(begin,end);
        return Result.success(userCount);
    }


    @GetMapping("/orderStatistics")
    @ApiOperation("订单数据统计")
    public Result<OrderCountVO> orderCount(@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate begin, @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate end){

        OrderCountVO orderCount=reportService.getOrderCount(begin,end);
        return Result.success(orderCount);
    }


    @GetMapping("/top10")
    @ApiOperation("订单数据统计")
    public Result<SalesTop10ReportVO> top10(@DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate begin, @DateTimeFormat(pattern = "yyyy-MM-dd")LocalDate end){

        SalesTop10ReportVO top10=reportService.getSalesTop10(begin,end);
        return Result.success(top10);
    }



    @GetMapping("/export")
    @ApiOperation("导出运营数据报表")
    public void export(HttpServletResponse response) throws IOException {

       reportService.getExport(response);

    }
}
